<?php

class PayoutReportController extends Controller
{
	public function actionIndex()
	{
		$connection = Yii::app()->db;

        if ( $_POST ) {
        	$year = $_POST['year'];
        }
		else {
			$year = date("Y");
		}
		
		$sql = "SELECT year, week_no, SUM(payout) AS total_payout, SUM(bv_personal) as total_bv
		               FROM gn_payouts 
		              WHERE year=$year AND member_id > 1
		               GROUP BY year, week_no
		               ORDER BY year, week_no DESC ";
		
		$command = $connection->createCommand($sql);
	    $dataReader = $command->query();

        $payout_data = array();
	    while ( $data = $dataReader->read() ) {
	    	array_push($payout_data, $data);
		}  	
		
		$this->render('index', array( 'payout_data'=> $payout_data ) );
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}